//
//  NoticeApi.m
//  Api
//
//  Created by CPX on 2018/7/10.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "NoticeApi.h"

/**
 通知页面接口
 @author yzl
 */
@implementation NoticeApi

+ (void)getNoticeListWithSuccess:(Success)success failure:(Failure)failure{
//    NSString *url = @"http://172.16.20.3:8000/message/message/notice";
    NSString *url = [NSString stringWithFormat:@"%@%@",RootURL,NoticeList];
//    NSString *p = @"Token eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NSwiZXhwIjoxNTQxODM4MDg5fQ.--57_E3aQXS0AB2CON5rqIk8916firPuEMwGfNfFWWw";
    NSMutableDictionary *dic = [self header];
//    dic[@"Authorization"] = p;
    [NetworkManagerV3 GETWithURL:url header:dic params:@{@"limit":@(100),@"offset":@(0)} success:^(id response) {
        if ([self dealWithResponse:response]) {
            success(response[@"data"]);
        }
        else{
            NSError *error = [NSError errorWithDomain:APPResponseError code:10001 userInfo:response];
            failure(error);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

+ (void)getSystemNoticeListWithSuccess:(Success)success failure:(Failure)failure{
    NSString *url = [NSString stringWithFormat:@"%@%@",RootURL,SystemNoticeList];
//    NSString *p = @"Token eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NSwiZXhwIjoxNTQxODM4MDg5fQ.--57_E3aQXS0AB2CON5rqIk8916firPuEMwGfNfFWWw";
    NSMutableDictionary *dic = [self header];
//    dic[@"Authorization"] = p;
    [NetworkManagerV3 GETWithURL:url header:dic params:nil success:^(id response) {
        if ([self dealWithResponse:response]) {
            success(response[@"data"]);
        }
        else{
            NSError *error = [NSError errorWithDomain:APPResponseError code:10001 userInfo:response];
            failure(error);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

+ (void)updateNoticeRead:(NSInteger )noticeId success:(Success)success failure:(Failure)failure{
    NSString *url = [NSString stringWithFormat:@"%@%@/%ld",RootURL,NoticeList,noticeId];
    [NetworkManagerV3 PUTWithURL:url header:[self header] params:@{} success:^(id response) {
        if ([self dealWithResponse:response]) {
            success(response[@"data"]);
        }
        else{
            NSError *error = [NSError errorWithDomain:APPResponseError code:10001 userInfo:response];
            failure(error);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

@end
